#ifndef _INCLUDED_RPC_FUNCTION_TABLE_H_
#define _INCLUDED_RPC_FUNCTION_TABLE_H_

#include <map>
#include "rpc.h"
#include "serialize.h"

template<typename Handler>
class rpc_function_table
{
	typedef std::map<int,function_stub<Handler>*> id2function_t;
	id2function_t functions_;
public:
	rpc_function_table();
	void dispatch_rpc_function(const rpc_message& msg,Handler handler)
	{
		id2function_t::iterator it = functions_.find(msg.rpc_id);
		if(it != functions_.end())
		{
			it->second->call(msg.arg_str,msg.arg_str_length,handler);
		}
		else
		{
			//todo handle error 
		}
	}
	void register_rpc(int id,function_stub<Handler>* f){functions_.insert(std::make_pair(id,f));}
};

#endif